<template>
    <div class="song-list">
        <!-- 歌单详情 -->
        <van-nav-bar
            title="歌单详情"
            left-text="返回"
            left-arrow
            @click-left="onClickLeft"
        />
        <div class="header">
            <img :src="song.logo" alt="">
            <h4>{{song.dissname}}</h4>
            <div class="nick">
                <img :src="song.headurl" alt="">
                <span>{{song.nickname}}</span>
            </div>
            <span>播放量:{{song.visitnum|numFilter(1)}}万</span>
        </div>
        <div class="list">
            <van-list
            v-model="loading"
            :finished="finiished"
            finished-text="没有更多了"
            @load="onLoad"
            >
            <div v-for="(item,index) in list" :key="index" :title="item" class="song">
                <h3>{{item.songname}}</h3>
                <div class="singers">
                    <span v-for="(singer,index) in item.singer" :key="singer.id">
                        {{singer.name}}
                        <span v-show="index!=item.singer.length-1">/</span>
                    </span>
                    <span v-show="item.albumname">
                        <span>.</span>
                        <span>{{item.albumname}}</span>
                    </span>
                </div>
            </div>
            </van-list>
        </div>
    </div>
</template>
<script>

export default{
    data(){
        return{
            song:{
                dissname:"",//标题
                logo:"",//歌单logo
                headurl:"",//歌单制作者头像
                nickname:"",//歌单制作者昵称
                visitnum:0,//歌单播放量
            },
            songlist:[],
            songnum:0,
            list:[],
            loading:false,
            finiished:false,
        };
    },
    created(){
        this.getListData()
    },
    methods:{
        getListData(){
            this.$request('get','/songlist?id='+this.$route.params.id)
            .then((res)=>{
                console.log(res)
                this.song.dissname=res.data.dissname
                this.song.logo=res.data.logo
                this.song.headurl=res.data.headurl
                this.song.nickname=res.data.nickname
                this.song.visitnum=res.data.visitnum
                this.songlist=res.data.songlist
                this.songnum=res.data.songnum
            })
        },
        onClickLeft(){
            window.history.length > 1 ? this.$router.go(-1) : this.$router.push('/')
        },
        onLoad(){
            setTimeout(()=>{
                this.list=this.list.concat(this.songlist.splice(0,10))
                this.loading=false;
                if(this.list.length>=this.songnum){
                    this.finiished=true;
                }
            },1000);
        },
    },
    filters:{
        //处理播放量显示格式
        numFilter(value,num){
            //把小数位固定为1位
            return parseFloat(value/10000).toFixed(num)
        }
    }
    
}
</script>
<style scoped>
.header > img{
    width: 50%;
    border-radius: 1rem;
}
.nick{
    overflow: hidden;
}
.nick > img{
    width: 1.5rem;
    border-radius: 50%;
    margin-right: 0.5rem;
}
.nick > span{
    height: 2rem;
    display: inline-block;
    vertical-align: middle;
    font-size: 0.8rem;
}
.header > span{
    font-size: 0.9rem;
}

.song{
    margin-bottom: 1rem;
}
.song>h3{
    text-align: left;
    font-size: 1rem;
    padding: 0 2rem;
    margin: 0;
}
.singers{
    text-align: left;
    padding: 0 2rem;
}
.singers span{
    font-size: 0.8rem;
    color: gray;
}
.singers>span:nth-last-child(1)>span:nth-child(1){
    margin: 0 0.3rem;
    font-weight: 900;
    color: red;
}
</style>
